/**
 * @author alex
 */

Namespace("sketch.decorators");

(function($){
	// using
	var dec = sketch.decorators,
		fwk = sketch.framework;
	
 	dec.DebugDecorator = klass(fwk.UIElementDecorator, {
        _constructor:function(){
            this.top = 0;
            this.left = 0;
            this.text = '';
            this._parentChanged = EventHandler(this, this.parentChanged);
 	    },
        attach : function(element){            
 		    dec.DebugDecorator.Super.attach.call(this, element);
            if(this.element.debugInfo !== undefined){ 		                        
 		        this.updatePosition();
                this.parentChanged();
                this.element.properties.propertyChanged.bind(this._parentChanged);                 
            }            
 	    },
        detach : function(element){
            this.element.properties.propertyChanged.unbind(this._parentChanged); 
 	    },
        parentChanged : function(){ 		    
 			this.text = this.element.debugInfo(); 		    
 		    this.updatePosition();
 	    },
 	    updatePosition : function(){
 		    var rect = this.element.getBoundaryRect();
 		    this.left = rect.x + rect.width;
 		    this.top = rect.y; 		    
 	    },
        draw : function(context){
            context.save();
            context.font = "bold 12px sans-serif";
            context.fillText(this.text, this.left, this.top);        
            context.restore();
        }
    });
 	
})(jQuery);